package com.lww.feature.test.io.inputstream;

import org.junit.Test;
import sun.font.FontUtilities;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * author: liweiwei
 * Date: 2018/12/27
 */
public class InputStream {

    /**
     * skip方法的实现方式是读取相应的位.
     * read(byte b[], int off, int len)中的off是真的b[]的
     */
    @Test
    public void read() throws IOException {
        File file = new File("/Users/lww/IdeaProjects/code/myproject/test/src/main/java/com/lww/feature/test/io/inputstream/0-9");
        FileInputStream fileInputStream = new FileInputStream(file);
        byte b[] = new byte[10];
        fileInputStream.skip(1);
        int read = fileInputStream.read(b, 5, 5);
        System.out.println(read);
        for (byte b1 : b) {
            System.out.println((char)b1);
        }
    }


    @Test
    public void closejdk7() throws IOException, InterruptedException {
        File file = new File("/Users/lww/IdeaProjects/code/myproject/test/src/main/java/com/lww/feature/test/io/inputstream/0-9");
        try(FileInputStream fileInputStream = new FileInputStream(file)) {
            byte b[] = new byte[10];
            fileInputStream.skip(1);
            int read = fileInputStream.read(b, 5, 5);
            System.out.println(read);
            for (byte b1 : b) {
                System.out.println((char)b1);
            }
        }
        Thread.sleep(1000000);

    }


}
